{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "test_data/gray/147_B_2_R_L_1.jpg\n",
      "test_data/gray/KakaoTalk_20200611_122409696_01.jpg\n",
      "test_data/gray/KakaoTalk_20200611_122409696_04.jpg\n",
      "test_data/gray/sample2.jpg\n",
      "test_data/gray/KakaoTalk_20200611_122409696_02.jpg\n",
      "test_data/gray/sample.PNG\n",
      "test_data/gray/127_F_2_W_D_1.jpg\n",
      "All Done\n"
     ]
    }
   ],
   "source": [
    "import cv2\n",
    "import os\n",
    "import numpy as np\n",
    "from PIL import Image\n",
    " \n",
    "path = \"test_data/\"\n",
    "imagePaths = [os.path.join(path,file_name) for file_name in os.listdir(path)]\n",
    "count = 0\n",
    "for imagePath in imagePaths:\n",
    "    if imagePath.split(\"/\")[-1] == \"out\":\n",
    "        continue\n",
    "    if imagePath.split(\"/\")[-1] == \"gray\":\n",
    "        continue\n",
    "    #print(imagePath)\n",
    "    count += 1\n",
    "    img = Image.open(imagePath)\n",
    "    img_numpy = np.array(img, 'uint8')\n",
    "    gray = cv2.cvtColor(img_numpy, cv2.COLOR_BGR2GRAY) #바꾸려는 img가 이미 gray이면 에러남\n",
    "    cv2.imwrite(\"test_data/gray\"+ imagePath.split(\"/\")[-1], gray)\n",
    "    print(\"Gray Scale! - test_data/gray/\"+ imagePath.split(\"/\")[-1])\n",
    "print(\"All Done\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
